package cz.cvut.fit.web.nakupniSeznam.ws.conv;

import java.net.URI;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import cz.cvut.fit.web.nakupniSeznam.data.Category;

@XmlRootElement(name = "category")
@XmlType(propOrder = { "id", "mobileId", "name", "lastChanged", "uri"})
public class CategoryConverter extends AbstractConverter {

	public CategoryConverter() {
		this.category = new Category();
		this.mobileId = null;
		this.expand = false;
	}

	public CategoryConverter(Category category, URI uri) {
		super();

		this.category = category;
		this.mobileId = null;
		this.uri = resolveURI(uri);
		this.expand = true;
	}
	
	public CategoryConverter(Category category) {
		super();

		this.category = category;
		this.mobileId = null;
		this.uri = resolveURI(uri);
		this.expand = false;
	}
	
	@Override
	protected URI resolveURI(URI uri) {
		String s = uri.getPath().replaceFirst("/categor.*", "/category/");
		URI listUri = URI.create(s + this.category.getId());
		URI resolvedUri = uri.resolve(listUri);
		return resolvedUri;
	}

	private Category category;
	private Long mobileId;
	
	

	@XmlElement
	public Long getId() {
		return this.category.getId();
	}

	@XmlElement
	public String getName() {
		return this.category.getName();
	}

	public void setId(Long id) {
		this.category.setId(id);
	}


	public void setName(String name) {
		this.category.setName(name);
	}

	public Category retrieveRepresentation() {
		return category;
	}

	@XmlElement
	public Long getMobileId() {
		return mobileId;
	}

	public void setMobileId(Long mobileId) {
		this.mobileId = mobileId;
	}
	
	@XmlElement
	public Long getLastChanged() {
		return this.category.getLastChanged();
	}
	
	public void setLastChanged(Long lastChanged) {
		this.category.setLastChanged(lastChanged);
	}
	
	@XmlElement
	public URI getUri() {
		return super.getUri();
	}
	
	
}
